package com.daocao.ds.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;


import com.daocao.ds.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/31.
 */

public class StarNumberView extends LinearLayout {
    @BindView(R.id.star_one)
    ImageView starOne;
    @BindView(R.id.star_two)
    ImageView starTwo;
    @BindView(R.id.star_three)
    ImageView starThree;
    @BindView(R.id.star_four)
    ImageView starFour;
    @BindView(R.id.star_five)
    ImageView starFive;

    public StarNumberView(Context context) {
        super(context);
        init(context, null);
    }

    public StarNumberView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public StarNumberView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        inflate(context, R.layout.layout_star_number, this);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.bind(this);
    }

    public void setStar(int number) {
        switch (number) {
            case 0:
                starOne.setImageResource(R.mipmap.img_star_uncheck);
                starTwo.setImageResource(R.mipmap.img_star_uncheck);
                starThree.setImageResource(R.mipmap.img_star_uncheck);
                starFour.setImageResource(R.mipmap.img_star_uncheck);
                starFive.setImageResource(R.mipmap.img_star_uncheck);
                break;
            case 1:
                starOne.setImageResource(R.mipmap.img_star_check);
                starTwo.setImageResource(R.mipmap.img_star_uncheck);
                starThree.setImageResource(R.mipmap.img_star_uncheck);
                starFour.setImageResource(R.mipmap.img_star_uncheck);
                starFive.setImageResource(R.mipmap.img_star_uncheck);
                break;
            case 2:
                starOne.setImageResource(R.mipmap.img_star_check);
                starTwo.setImageResource(R.mipmap.img_star_check);
                starThree.setImageResource(R.mipmap.img_star_uncheck);
                starFour.setImageResource(R.mipmap.img_star_uncheck);
                starFive.setImageResource(R.mipmap.img_star_uncheck);
                break;
            case 3:
                starOne.setImageResource(R.mipmap.img_star_check);
                starTwo.setImageResource(R.mipmap.img_star_check);
                starThree.setImageResource(R.mipmap.img_star_check);
                starFour.setImageResource(R.mipmap.img_star_uncheck);
                starFive.setImageResource(R.mipmap.img_star_uncheck);
                break;
            case 4:
                starOne.setImageResource(R.mipmap.img_star_check);
                starTwo.setImageResource(R.mipmap.img_star_check);
                starThree.setImageResource(R.mipmap.img_star_check);
                starFour.setImageResource(R.mipmap.img_star_check);
                starFive.setImageResource(R.mipmap.img_star_uncheck);
                break;
            case 5:
                starOne.setImageResource(R.mipmap.img_star_check);
                starTwo.setImageResource(R.mipmap.img_star_check);
                starThree.setImageResource(R.mipmap.img_star_check);
                starFour.setImageResource(R.mipmap.img_star_check);
                starFive.setImageResource(R.mipmap.img_star_check);
                break;
        }
    }
}
